package uk.ac.ebi.bioinvindex.model.impl;

import uk.ac.ebi.bioinvindex.model.impl.term.PublicationStatusImpl;
import uk.ac.ebi.bioinvindex.model.impl.xref.PublicationXrefImpl;

import javax.persistence.*;
import java.util.Collection;


/**
 * @author brandizi
 */
@Entity
@Table(name = "publication")
public class PublicationImpl extends HasReferencesImpl<PublicationXrefImpl> {

	private String title, authorList;
	private StudyImpl study;
	private InvestigationImpl investigation;
	private PublicationStatusImpl status;

	protected PublicationImpl() {
	}


	public PublicationImpl(String title, String authorList) {
		this.setTitle(title);
		this.setAuthorList(authorList);
	}


	public String getTitle() {
		return this.title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getAuthorList() {
		return this.authorList;
	}

	public void setAuthorList(String authorList) {
		this.authorList = authorList;
	}

	@ManyToOne(targetEntity = uk.ac.ebi.bioinvindex.model.impl.StudyImpl.class)
	@JoinColumn(name = "study_id", nullable = true)
	protected StudyImpl getStudy() {
		return this.study;
	}

	protected void setStudy(StudyImpl study) {
		this.study = study;
	}


	@ManyToOne(targetEntity = uk.ac.ebi.bioinvindex.model.impl.InvestigationImpl.class)
	@JoinColumn(name = "investigation_id", nullable = true)
	public InvestigationImpl getInvestigation() {
		return investigation;
	}

	public void setInvestigation(InvestigationImpl investigation) {
		this.investigation = investigation;
	}

	@OneToMany(
			targetEntity = uk.ac.ebi.bioinvindex.model.impl.xref.PublicationXrefImpl.class
			, mappedBy = "owner"
			, cascade = CascadeType.ALL
	)
	public Collection<PublicationXrefImpl> getXrefs() {
		return super.getXrefs();
	}

//	public void addXref(PublicationXrefImpl ref) {
//		super.addXref(ref);
//	}

	@OneToOne(targetEntity = PublicationStatusImpl.class)
	public PublicationStatusImpl getStatus() {
		return this.status;
	}

	public void setStatus(PublicationStatusImpl status) {
		this.status = status;
	}

	public String toString() {
		return "Publication Title:\n" + this.getTitle() + "\n(" + this.getAuthorList() + ")\n\n";
	}

}
